<?php
class Login_Index_Action extends NICED_Action 
{       
	public function execute() 
	{
		$controller = $this->getController();
		$request    = $controller->getRequest();			
        $act        = $request->loadParam("act");
        $user_name  = $request->loadParam("user_name");
        $password   = $request->loadParam("password");
        $call_back_url = $request->loadParam("call_back_url");
        if (!$call_back_url)
        {
            //$call_back_url = NICED_URL::buildURL(SC::get("default_request_name"));
            $call_back_url = NICED_URL::buildURL("admin.index");
        }

		try
		{
		    $model      = $controller->getModel('Login.Index');

            if (!$act)
            {
                return self::SUCCESS;
            }

            $model->login($user_name, $password);
            $user_id = Session::getUserId();
            //header("Location: /admin/index");
            header("Location: ".$call_back_url);
		}
		catch (Exception $e)
		{
			$controller->handleException(new NICED_Exception($e->getMessage()));

			return self::SUCCESS;
		}

		return self::SUCCESS;
	}

}//end class
